using System.Runtime.InteropServices;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Graphics.PackedVector;

namespace XDL.Framework.Particles
{
    /// <summary>
    /// Custom vertex structure for drawing point sprite particles.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct ParticleVertex : IVertexType
    {
        // Stores which corner of the particle quad this vertex represents.
        public Short2 Corner;
        
        // Stores the position of the particle.
        public Vector3 Position;

        // Stores the velocity of the particle.
        public Vector3 Velocity;

        // Four random values, used to make each particle look slightly different.
        public Color Random;

        // Time left for this particle (in seconds).
        public float Lifetime;
        
        /// <summary>
        /// Helper member for custom usage
        /// </summary>
        /// <remarks>CPU only information</remarks>
        public float Tag;

        // Describe the layout of this vertex structure.
        static readonly VertexDeclaration s_vertexDeclaration = new VertexDeclaration
        (
            new VertexElement(0, VertexElementFormat.Short2,
                                 VertexElementUsage.Position, 0),

            new VertexElement(4, VertexElementFormat.Vector3,
                                 VertexElementUsage.Position, 1),

            new VertexElement(16, VertexElementFormat.Vector3,
                                  VertexElementUsage.Normal, 0),

            new VertexElement(28, VertexElementFormat.Color,
                                  VertexElementUsage.Color, 0),

            new VertexElement(32, VertexElementFormat.Single,
                                  VertexElementUsage.TextureCoordinate, 0),
            new VertexElement(36, VertexElementFormat.Single,
                                  VertexElementUsage.TextureCoordinate, 1)           
        );
    
        VertexDeclaration IVertexType.VertexDeclaration
        {
	        get 
            { 
                return s_vertexDeclaration;
            }
        }
    }
}
